<!--<script type="text/javascript" src="https://static-oss.qutoutiao.net/game/sdk/h5.v1.0.0.js"></script>-->

<if condition="($Think.cookie.hidePopupNum eq 1) or ($Think.cookie.QSorderNo eq 1)" >
    <elseif condition="($Think.cookie.qudaoJgTypeNum eq 1) or ($Think.cookie.qudaoJgTypeNum eq 2)"/>
    <!-- 首页 支付页 返回弹窗 -->
    <include file="Public/zhifu_share1" />
    <else />
</if>

<if condition="$channel eq qudao245">
    <script type="text/javascript" src="https://newidea4-gamecenter-frontend.1sapp.com/sdk/prod/h5.v1.0.0.js"></script>
    <else />
</if>

<script src="__PUBLIC__/js/qrcode.js"></script>
<script>
    var orderid="<!--{$Think.cookie.orderid}-->";
    var csNameJump="https://wx.ddznzj.com"+"<!--{$csNameJump}-->";
    var uid='<!--{$Think.cookie.uid}-->';


    if(orderid){//支付页循环查询
        setInterval(function(){
            $.getJSON("<!--{:U('Index/selectLoop','',false)}-->",{orderid:orderid},function(data){
                if(data){
                    location.href='<!--{$csNameJump}-->';
                }else{
                    console.log(data);
                }
            });
        },1500);
    }

    /*qudao245支付接口加载类*/
    function payMoney245(getOrderid,jumpUrl){
        $.getJSON("<!--{:U('Index/selectLoop','',false)}-->",{orderid:orderid},function(data){
            if(data){
                console.log(data);
                if(jumpUrl){location.href=jumpUrl;
                }else{location.href=csNameJump;
                }
            }else{
                if(getOrderid){
                    console.log('getOrderid');
                    qttGame.pay({openId:'<!--{$Think.cookie.QTTopenid}-->', money: '<!--{$Think.cookie.price}-->'*100+'', appId: '<!--{$Think.cookie.QTTappid}-->', platform: 'qtt',
                        notifyUrl: 'https://hy.yixueqm.com/zhiming/index.php/Home-Index-notify_urlwx?orderid='+getOrderid,gameName: '知命',ext:'{"orderid":""}'});
                    //var orderid=getOrderid;
                }else{
                    console.log('Orderid');
                    qttGame.pay({openId:'<!--{$Think.cookie.QTTopenid}-->', money: '<!--{$Think.cookie.price}-->'*100+'', appId: '<!--{$Think.cookie.QTTappid}-->', platform: 'qtt',
                        notifyUrl: 'https://hy.yixueqm.com/zhiming/index.php/Home-Index-notify_urlwx?orderid=<!--{$Think.cookie.orderid}-->',gameName: '知命',ext:'{"orderid":"<!--{$Think.cookie.orderid}-->"}'});
                }
            }
        });


        console.log(orderid);

        if(orderid){
            setInterval(function(){
                $.getJSON("<!--{:U('Index/selectLoop','',false)}-->",{orderid:orderid},function(data){
                    if(data){
                        console.log(data);
                        if(jumpUrl){
                            location.href=jumpUrl;
                        }else{
                            location.href=csNameJump;
                        }

                    }else{
                        console.log(data);
                    }
                });
            },2000);
        }else{
            setInterval(function(){
                $.getJSON("<!--{:U('Index/selectLoop','',false)}-->",{orderid:getOrderid},function(data){
                    if(data){
                        console.log(data);
                        if(jumpUrl){
                            location.href=jumpUrl;
                        }else{
                            location.href=csNameJump;
                        }

                    }else{
                        console.log(data);
                    }
                });
            },2000);
        }
    }

    /*qudao135 花生地铁*/
    function payMoney135(payType){
        //closePay();
        sessionStorage.setItem("payType",payType);

        var payType = payType;
        var bussiCode = 'business006';
        var bussiDesc = '知命';
        var goodsCode = 'zhimingQudao135';
        var goodsDesc = '知命';
        var money = '<!--{$Think.cookie.price}-->';
        var userId='<!--{$Think.cookie.uid}-->';
        var extContent = orderid;

        if(get_os()==2){
            setupWebViewJavascriptBridge(function(bridge) {
                bridge.callHandler('peanutPay',{"payType":payType,"bussiCode":bussiCode,"bussiDesc":bussiDesc,"goodsCode":goodsCode,"goodsDes":goodsDesc,"price":money,"userId":userId,"extContent":extContent}, function responseCallback(responseData) {});
            });
        }else{
            window.news.peanutPay(payType,bussiCode,bussiDesc,goodsCode,goodsDesc,money,userId,extContent);
        }
    };
    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
        if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
//        WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
        WVJBIframe.src='https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
    }

    function PayResultCallBack(res){
        var payType = sessionStorage.getItem("payType");

        if(get_os()==2){
        }else{
            var res = JSON.parse(res);
        }
        if(res.resultCode==1){
            if(res.extContent){
                var orderid=res.extContent;
            }
            layer.load();
//           alert('成功:'+orderid);
//            if(payType==3){
//                setTimeout(function(){
//                    $.getJSON("<!--{:U('Index/notify_urlwx','',false)}-->",{out_trade_no:orderid},function(data){//回调入库
//                        location.href=csNameJump;
//                        layer.closeAll('loading');
//                    });
//                },500)
//            }else{
                setTimeout(function(){
                    $.getJSON("<!--{:U('Index/notify_urlwx','',false)}-->",{orderid:orderid},function(data){//回调入库
                        location.href=csNameJump;
                        layer.closeAll('loading');
                    });
                },500)
//           }

            setTimeout(function(){
                location.href=csNameJump;
                layer.closeAll('loading');
            },5000)

        }else if(res.resultCode==2){
            showAlert("#payWait-msg");
        }else if(res.resultCode==0){
            showAlert("#payError-msg");
        }
    }

    /*系统类型检测*/
    function get_os() {
        var userAgent = navigator.userAgent || navigator.vendor || window.opera;
        if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) {
            return 2;
        }
        else {
            return 1;
        }
    }


    /*爱豆支付*/
    function aidouPay(){
        android.heimiPay("{\"uid\":"+uid+",\"gold\":"+price+",\"price\":"+price*100+",\"title\":'知命服务',\"content\":'知命测算',\"url\":'"+csNameJump+"',\"orderid\":'"+orderid+"'}");
    }

    /*渠道直接支付触发*/
    function zhifuPopup(){
        if(channel=='C001'){
            payMoney('wx');
            exit;
        }
        /*头条精选*/
        if(channel=='qudao26'){
            payMoneyTtjx();
            exit;
        }
        /*万娱  万年历*/
        if(channel=='YSWNL_iOS'){
            selectLoop();
            payMoneyWanYu();
            exit;
        }

        //微信扫码检测
        if('<!--{$pc}-->'==1){
            selectLoop();
        }

        //谷歌支付
        if('<!--{$Think.cookie.paytypeGg}-->'==1){
            console.log('谷歌支付');
            if(channel=='ssh_google'){//美元价格
                payTypeGugeSsh_google();
            }else{
                payTypeGuge();
            }

            exit;
        }
    }

    //微信扫码
    var wxsaoma='<!--{$wxsaoma}-->';
    if(wxsaoma ==''){
        $('#qrcode').css('display','none');
    }
    var qrcode = new QRCode('qrcode', {
        text: wxsaoma,  //链接
        width: 120,
        height: 120,
        colorDark : '#000000',
        colorLight : '#ffffff',
        correctLevel : QRCode.CorrectLevel.H
    });

    //订单循环检测
    function selectLoop(){
        payBoolean=setInterval(function(){
            $.getJSON("<!--{:U('Index/selectLoop','',false)}-->",{orderid:orderid},function(data){
                console.log(data);
                if(data){
                    clearInterval(payBoolean)
                    var oli = layer.load();
                    setTimeout(function(){
                        layer.closeAll('loading');
                        layer.msg('支付成功', {icon: 1});
                        setTimeout(function(){
                            location.href=csNameJump;
                        },1300);
                    },1000);
                }
            });
        },2000)
    }


    function payMoneyWanYu(){
        console.log("万娱测试");
        window.webkit.messageHandlers.catchPayParam.postMessage("{\"orderId\":\"<!--{$Think.cookie.orderid}-->\"," +
        "\"productCode\":\"<!--{$Think.cookie.WYproductId}-->\"," +
        "\"amout\":\"<!--{$Think.cookie.price}-->\"," +
        "\"productName\":\"知命测算\"," +
        "\"serverId\":\"123456789\"}");
    }
    function payTypeGuge(){
        console.log('谷歌');
        android.pay(1,"{\"orderId\":\"<!--{$Think.cookie.orderid}-->\"," +
                "\"notifyUrlwx\":\"https://hy.yixueqm.com/zhiming/index.php/home-index-notify_urlwx?orderid=<!--{$Think.cookie.orderid}-->\"," +
        "\"returnUrlwx\":\"https://hy.yixueqm.com/zhiming/index.php/Home-Index-return_urlwx?orderid=<!--{$Think.cookie.orderid}-->&csName=<!--{$Think.cookie.orderidnum}-->\"," +
        "\"price\":\"<!--{$Think.cookie.price}-->\"," +
                "\"productId\":\"smgold28\"," +
                "\"productName\":\"知命测算\"}")
    }
    function payTypeGugeSsh_google(){
        console.log('谷歌ssh28');
        android.pay(1,"{\"orderId\":\"<!--{$Think.cookie.orderid}-->\"," +
        "\"notifyUrlwx\":\"https://hy.yixueqm.com/zhiming/index.php/home-index-notify_urlwx?orderid=<!--{$Think.cookie.orderid}-->\"," +
        "\"returnUrlwx\":\"https://hy.yixueqm.com/zhiming/index.php/Home-Index-return_urlwx?orderid=<!--{$Think.cookie.orderid}-->&csName=<!--{$Think.cookie.orderidnum}-->\"," +
        "\"price\":\"<!--{$Think.cookie.price}-->\"," +
        "\"productId\":\"ssh28\"," +
        "\"productName\":\"神算汇测算\"}")
    }

</script>